package com.kazusa.myservlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;


/*
* Cookie是浏览器技术，即使关闭服务器也依然存在可以进行获取
* */
@WebServlet("/getCookie")
public class CookieGet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[]cookies=request.getCookies();
        if(cookies!=null&&cookies.length>0){
            for(Cookie cookie:cookies){
                String name = cookie.getName();
                String value=cookie.getValue();
                System.out.println("Cookie Name: "+name+" Cookie Value: "+value);
            }
        }
    }
}
